package cz.proks.easyhelpdesk.gwt;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceHistoryMapper;

import cz.proks.easyhelpdesk.gwt.activity.DefaultActivity;
import cz.proks.easyhelpdesk.gwt.activity.HelpdeskMainActivity;
import cz.proks.easyhelpdesk.gwt.activity.HelpdesksActivity;
import cz.proks.easyhelpdesk.gwt.activity.LogoutActivity;
import cz.proks.easyhelpdesk.gwt.activity.NewHelpdeskActivity;
import cz.proks.easyhelpdesk.gwt.activity.NewTicketActivity;
import cz.proks.easyhelpdesk.gwt.activity.OAuthActivity;
import cz.proks.easyhelpdesk.gwt.activity.SettingsActivity;
import cz.proks.easyhelpdesk.gwt.activity.ThreadActivity;
import cz.proks.easyhelpdesk.gwt.activity.UserActivity;
import cz.proks.easyhelpdesk.gwt.activity.WelcomeActivity;
import cz.proks.easyhelpdesk.gwt.place.DefaultPlace;
import cz.proks.easyhelpdesk.gwt.place.HelpdeskMainPlace;
import cz.proks.easyhelpdesk.gwt.place.HelpdesksPlace;
import cz.proks.easyhelpdesk.gwt.place.LogoutPlace;
import cz.proks.easyhelpdesk.gwt.place.NewHelpdeskPlace;
import cz.proks.easyhelpdesk.gwt.place.NewTicketPlace;
import cz.proks.easyhelpdesk.gwt.place.OAuthPlace;
import cz.proks.easyhelpdesk.gwt.place.SettingsPlace;
import cz.proks.easyhelpdesk.gwt.place.ThreadPlace;
import cz.proks.easyhelpdesk.gwt.place.UserPlace;
import cz.proks.easyhelpdesk.gwt.place.WelcomePlace;

public class HelpdeskActivityMapper implements ActivityMapper {
	private ClientFactory clientFactory;	
	private PlaceHistoryMapper placeMapper;
	
	public HelpdeskActivityMapper(ClientFactory clientFactory, PlaceHistoryMapper placeMapper) {
		super();
		this.clientFactory = clientFactory;
		this.placeMapper = placeMapper;
	}


	@Override
	public Activity getActivity(Place place) {	    
	    // !! ORDER OF PLACES MATTER FOR INSTANCE-OF COMPARISON - place can extend other place !!
	    
	    if (place instanceof DefaultPlace)
	        return new DefaultActivity(place, clientFactory, placeMapper);	  	    
	    
	    else if (place instanceof WelcomePlace)
			return new WelcomeActivity((WelcomePlace) place, clientFactory, placeMapper);
	    
	    else if (place instanceof LogoutPlace)
            return new LogoutActivity((LogoutPlace) place, clientFactory, placeMapper);
		
		else if (place instanceof OAuthPlace)
			return new OAuthActivity((OAuthPlace) place, clientFactory, placeMapper);
		
		else if (place instanceof HelpdesksPlace)
		    return new HelpdesksActivity((HelpdesksPlace) place, clientFactory, placeMapper);
		
		else if (place instanceof NewHelpdeskPlace)
		    return new NewHelpdeskActivity((NewHelpdeskPlace) place, clientFactory, placeMapper);				
		
		else if (place instanceof NewTicketPlace) 
		    return new NewTicketActivity((NewTicketPlace) place, clientFactory, placeMapper);
	    
		else if (place instanceof ThreadPlace) 
		    return new ThreadActivity((ThreadPlace) place, clientFactory, placeMapper);
	    
		else if (place instanceof SettingsPlace)
		    return new SettingsActivity((SettingsPlace) place, clientFactory, placeMapper);
	    
		else if (place instanceof UserPlace)
		    return new UserActivity((UserPlace) place, clientFactory, placeMapper);
	    
		else if (place instanceof HelpdeskMainPlace) 
            return new HelpdeskMainActivity((HelpdeskMainPlace) place, clientFactory, placeMapper);
		    
		return null;
	}	
}
